package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import entity.News;
import entity.ProductCategory;

public class NewsDao extends BaseDao{
   public Connection conn;
   public PreparedStatement pstmt;
   public ResultSet rs;
   public List<News> newsList(){
	   List<News> list=new ArrayList<News>();
	   try {
			conn=super.getConnection();

			String sql="SELECT * from easybuy_news ORDER BY createTime desc  limit  5";

			pstmt=conn.prepareStatement(sql);

			rs=pstmt.executeQuery();

			while (rs.next()) {
				News ne=new News();
			    ne.setId(rs.getInt("id"));
			    ne.setTitle(rs.getString("title"));
			    ne.setCreateTime(rs.getString("createTime"));
			    ne.setContent(rs.getString("content"));
				list.add(ne);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			super.closeAll(conn, pstmt, rs);
		}
	   return list;
   }
}
